@import '_variables';
@import '_mixins';
@import '_bootstrap-variables';
@import '_miniature';

$player-factor: 1.7; // 16/9
$video-info-margin-left: 44px;

@function getPlayerHeight($width){
  @return calc(#{$width} / #{$player-factor})
}

@function getPlayerWidth($height){
  @return calc(#{$height} * #{$player-factor})
}

@mixin playlist-below-player {
  width: 100% !important;
  height: auto !important;
  max-height: 300px !important;
  max-width: initial;
  border-bottom: 1px solid $separator-border-color !important;
}

.root {
  &.theater-enabled #video-wrapper {
    flex-direction: column;
    justify-content: center;

    $height: calc(100vh - #{$header-height} - #{$theater-bottom-space});

    #videojs-wrapper {
      width: 100%;
      height: $height;
    }

    ::ng-deep .video-js {
      height: $height;
      width: 100%;
      max-width: initial;
    }

    my-video-watch-playlist ::ng-deep .playlist {
      @include playlist-below-player;
    }
  }
}

.blocked-label {
  font-weight: $font-semibold;
}

#video-wrapper {
  $video-height: 66vh;

  background-color: #000;
  display: flex;
  justify-content: center;

  #videojs-wrapper {
    display: flex;
    justify-content: center;
    flex-grow: 1;
    height: $video-height;
  }

  .remote-server-down {
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    justify-content: center;
    background-color: #141313;
    width: 100%;
    font-size: 24px;
    height: 500px;

    @media screen and (max-width: 1000px) {
      font-size: 20px;
    }

    @media screen and (max-width: 600px) {
      font-size: 16px;
    }
  }

  ::ng-deep .video-js {
    width: 100%;
    max-width: getPlayerWidth(66vh);
    height: $video-height;

    // VideoJS create an inner video player
    video {
      outline: 0;
      position: relative !important;
    }
  }

  @media screen and (max-width: 600px) {
    #videojs-wrapper {
      height: getPlayerHeight(100vw) !important;
    }

    .remote-server-down,
    ::ng-deep .video-js {
      width: 100vw;
      height: getPlayerHeight(100vw) !important;
    }
  }
}

.alert {
  text-align: center;
  border-radius: 0;
}

.flex-direction-column {
  flex-direction: column;
}

#video-not-found {
  height: 300px;
  line-height: 300px;
  margin-top: 50px;
  text-align: center;
  font-weight: $font-semibold;
  font-size: 15px;
}

.video-bottom {
  display: flex;
  margin-top: 1.5rem;

  .video-info {
    flex-grow: 1;
    // Set min width for flex item
    min-width: 1px;
    max-width: 100%;

    .video-info-first-row {
      display: flex;

      & > div:first-child {
        flex-grow: 1;
      }

      .video-info-name {
        margin-right: 30px;
        min-height: 40px; // Align with the action buttons
        font-size: 27px;
        font-weight: $font-semibold;
        flex-grow: 1;
      }

      .video-info-first-row-bottom {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        width: 100%;
      }

      .video-info-date-views {
        align-self: start;
        margin-bottom: 10px;
        margin-right: 10px;
        font-size: 1em;
      }

      .video-info-channel {
        font-weight: $font-semibold;
        font-size: 15px;

        a {
          @include disable-default-a-behaviour;

          color: pvar(--mainForegroundColor);

          &:hover {
            opacity: 0.8;
          }

          img {
            @include avatar(18px);

            margin: -2px 5px 0 0;
          }
        }

        .video-info-channel-left {
          flex-grow: 1;

          .video-info-channel-left-links {
            display: flex;
            flex-direction: column;
            position: relative;
            line-height: 1.37;

            a:nth-of-type(2) {
              font-weight: 500;
              font-size: 90%;
            }

            a.single-link {
              margin-top: 7px;
            }
          }
        }

        my-subscribe-button {
          margin-left: 5px;
        }
      }

      my-feed {
        margin-left: 5px;
        margin-top: 1px;
      }

      .video-actions-rates {
        margin: 0 0 10px 0;
        align-items: start;
        width: max-content;
        margin-left: auto;

        .video-actions {
          height: 40px; // Align with the title
          display: flex;
          align-items: center;

          .action-button:not(:first-child),
          .action-dropdown,
          my-video-actions-dropdown {
            margin-left: 5px;
          }

          ::ng-deep.action-button {
            @include peertube-button;
            @include button-with-icon(21px, 0, -1px);
            @include apply-svg-color(pvar(--actionButtonColor));

            font-size: 100%;
            font-weight: $font-semibold;
            display: inline-block;
            padding: 0 10px 0 10px;
            white-space: nowrap;
            background-color: transparent !important;
            color: pvar(--actionButtonColor);
            text-transform: uppercase;

            &::after {
              display: none;
            }

            &:hover {
              opacity: 0.9;
            }

            &.action-button-like,
            &.action-button-dislike {
              filter: brightness(120%);

              .count {
                margin: 0 5px;
              }
            }

            &.action-button-like.activated {
              .count {
                color: pvar(--activatedActionButtonColor);
              }

              my-global-icon {
                @include apply-svg-color(pvar(--activatedActionButtonColor));
              }
            }

            &.action-button-dislike.activated {
              .count {
                color: pvar(--activatedActionButtonColor);
              }

              my-global-icon {
                @include apply-svg-color(pvar(--activatedActionButtonColor));
              }
            }

            &.action-button-support {
              color: pvar(--supportButtonColor);

              my-global-icon {
                @include apply-svg-color(pvar(--supportButtonColor));
              }
            }

            &.action-button-support {
              my-global-icon {
                ::ng-deep path:first-child {
                  fill: pvar(--supportButtonHeartColor) !important;
                }
              }
            }

            &.action-button-save {
              my-global-icon {
                top: 0 !important;
                right: -1px;
              }
            }

            .icon-text {
              margin-left: 3px;
            }
          }
        }

        .video-info-likes-dislikes-bar-outer-container {
          position: relative;
        }

        .video-info-likes-dislikes-bar-inner-container {
          position: absolute;
          height: 20px;
        }

        .video-info-likes-dislikes-bar {
          $likes-bar-height: 2px;
          height: $likes-bar-height;
          margin-top: -$likes-bar-height;
          width: 120px;
          background-color: #ccc;
          position: relative;
          top: 10px;

          .likes-bar {
            height: 100%;
            background-color: #909090;

            &.liked {
              background-color: pvar(--activatedActionButtonColor);
            }
          }
        }
      }
    }

    .video-info-description {
      margin: 20px 0;
      margin-left: $video-info-margin-left;
      font-size: 15px;

      .video-info-description-html {
        @include peertube-word-wrap;

        ::ng-deep a {
          text-decoration: none;
        }
      }

      .glyphicon, .description-loading {
        margin-left: 3px;
      }

      .description-loading {
        display: inline-block;
      }

      .video-info-description-more {
        cursor: pointer;
        font-weight: $font-semibold;
        color: pvar(--greyForegroundColor);
        font-size: 14px;

        .glyphicon {
          position: relative;
          top: 2px;
        }
      }
    }

    .video-attributes {
      margin-left: $video-info-margin-left;
    }

    .video-attributes .video-attribute {
      font-size: 13px;
      display: block;
      margin-bottom: 12px;

      .video-attribute-label {
        min-width: 142px;
        padding-right: 5px;
        display: inline-block;
        color: pvar(--greyForegroundColor);
        font-weight: $font-bold;
      }

      a.video-attribute-value {
        @include disable-default-a-behaviour;
        color: pvar(--mainForegroundColor);

        &:hover {
          opacity: 0.9;
        }
      }

      &.video-attribute-tags {
        .video-attribute-value:not(:nth-child(2)) {
          &::before {
            content: ', '
          }
        }
      }
    }
  }

  ::ng-deep .other-videos {
    padding-left: 15px;
    min-width: $video-miniature-width;

    @media screen and (min-width: 1800px - (3* $video-miniature-width)) {
      width: min-content;
    }

    .title-page {
      margin: 0 !important;
    }

    .video-miniature {
      display: flex;
      width: max-content;
      height: 100%;
      padding-bottom: 20px;
      flex-wrap: wrap;
    }

    .video-bottom {
      @media screen and (max-width: 1800px - (3* $video-miniature-width)) {
        margin-left: 1rem;
      }
      @media screen and (max-width: 500px) {
        margin-left: 0;
        margin-top: .5rem;
      }
    }
  }
}

my-video-comments {
  display: inline-block;
  width: 100%;
  margin-bottom: 20px;
}

// If the view is not expanded, take into account the menu
.privacy-concerns {
  z-index: z(dropdown) + 1;
  width: calc(100% - #{$menu-width});
}

@media screen and (max-width: $small-view) {
  .privacy-concerns {
    margin-left: $menu-width - 15px; // Menu is absolute
  }
}

:host-context(.expanded) {
  .privacy-concerns {
    width: 100%;
    margin-left: -15px;
  }
}

.privacy-concerns {
  position: fixed;
  bottom: 0;
  z-index: z(privacymsg);

  padding: 5px 15px;

  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(0, 0, 0, 0.9);
  color: #fff;

  .privacy-concerns-text {
    margin: 0 5px;
  }

  a {
    @include disable-default-a-behaviour;

    color: pvar(--mainColor);
    transition: color 0.3s;

    &:hover {
      color: #fff;
    }
  }

  .privacy-concerns-button {
    padding: 5px 8px 5px 7px;
    margin-left: auto;
    border-radius: 3px;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.3s;
    font-weight: $font-semibold;

    &:hover {
      background-color: #000;
    }
  }

  .privacy-concerns-okay {
    background-color: pvar(--mainColor);
    margin-left: 10px;
  }
}

@media screen and (max-width: 1600px) {
  .video-bottom .video-info .video-attributes .video-attribute {
    margin-bottom: 5px;
  }
}

@media screen and (max-width: 1300px) {
  .privacy-concerns {
    font-size: 12px;
    padding: 2px 5px;

    .privacy-concerns-text {
      margin: 0;
    }
  }
}

@media screen and (max-width: 1100px) {
  #video-wrapper {
    flex-direction: column;
    justify-content: center;

    my-video-watch-playlist ::ng-deep .playlist {
      @include playlist-below-player;
    }
  }

  .video-bottom {
    flex-direction: column;

    ::ng-deep .other-videos {
      padding-left: 0 !important;

      ::ng-deep .video-miniature  {
        flex-direction: row;
        width: auto;
      }
    }
  }
}

@media screen and (max-width: 600px) {
  .video-bottom {
    margin-top: 20px !important;
    padding-bottom: 20px !important;

    .video-info {
      padding: 0;

      .video-info-first-row {

        .video-info-name {
          font-size: 20px;
          height: auto;
        }
      }
    }
  }

  ::ng-deep .other-videos .video-miniature  {
    flex-direction: column;
  }

  .privacy-concerns {
    width: 100%;
  }
}

@media screen and (max-width: 450px) {
  .video-bottom {
    .action-button .icon-text {
      display: none !important;
    }

    .video-info .video-info-first-row {
      .video-info-name {
        font-size: 18px;
      }

      .video-info-date-views {
        font-size: 14px;
      }

      .video-actions-rates {
        margin-top: 10px;
      }
    }

    .video-info-description {
      font-size: 14px !important;
    }
  }
}


// Special case for iOS, that takes into account the width for fullscreens
#video-wrapper ::ng-deep .video-js.vjs-fullscreen {
  max-width: unset;
}
